﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/header.js"></script>
    <link href="/lib/jquery/jquery-ui.min.css" rel="stylesheet" />
    <script src="/lib/jquery/jquery-ui.min.js"></script>
</head>
<body>
    <section class="container-fluid" style="background-color: white;">
        <form class="form-horizontal m15_t" id="form">
            <div class="tab-content">
                <input type="hidden" id="hdCmid" name="hdCmid" value="0">

                <div class="tab-pane fade in active" id="divCardMerchant">
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span> 卡商名称：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="cmname" maxlength="40" autocomplete="off" placeholder="名称长度必须介于 1 和 40 之间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span> 卡商代号：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="cmcode" maxlength="40" autocomplete="off" placeholder="代号长度必须介于 1 和 40 之间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>信用度：</label>
                        <select class="m15_l" name="cmcredit" id="cmcredit">
                            <option value="A">A</option>
                            <option value="B">B</option>
                            <option value="C">C</option>
                            <option value="D">D</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span> 延迟率：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="delayRate" maxlength="4" autocomplete="off" placeholder="延迟率只能为整数">
                        </div>
                    </div>
                    <!--<div class="form-group" id="divCardCommissionerUid">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>卡管专员ID：</label>
                        <select class="m15_l" name="cardCommissionerUid" id="cardCommissionerUid"></select>
                    </div>-->
                    <div class="form-group">
                        <label class="wd100 control-label"> 备注：</label>
                        <div class="wd250 m15_l">
                            <textarea style="height: auto;font-size: 12px;width: 100%;" type="text" id="remark" name="remark" maxlength="180"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </section>
    <script type="text/javascript">
        var validator = null;

        var cardCommissionerUid = $("select[name='cardCommissionerUid']");

        $(function () {
            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });
            FlashPay.Util.Ajax({
                type: "POST",
                url: "/User/GetSelectList",
                data: null,
                dataType: "json",
                contentType: "application/json",
                success: function (response) {

                    if (response != null) {
                        cardCommissionerUid.append("<option value=''>请选择</option>");
                        $.each(response, function (i, item) {
                            cardCommissionerUid.append("<option value='" + item.uId + "'>" + item.uLoginName + "</option >");
                        });
                    }
                    cover.Remove();
                },
                error: function (json) {
                    cover.Remove();
                }
            });

            validator = FlashPay.Util.Validator({
                formObj: $("#form"),
                rules: {
                    cmname: {
                        required: true,
                        rangelength: [1, 40]
                    },

                    cmcode: {
                        required: true,
                        rangelength: [1, 40]
                    },

                    delayRate: {
                        required: true,
                        digits: true,
                        isIntGtZero: true
                    },
                    //cardCommissionerUid: {
                    //    required: true
                    //}
                   
                },
                messages: {
                    cmname: {
                        required: "名称长度必须介于 1 和 40 之间",
                        rangelength: "名称长度必须介于 1 和 40 之间",
                    },

                    cmcode: {
                        required: "代号长度必须介于 1 和 40 之间",
                        rangelength: "代号长度必须介于 1 和 40 之间",
                    },

                    delayRate: {
                        required: "延迟率不能为空",
                        isIntGtZero: "延迟率必须大于0",
                        digits: "延迟率必须为整数",
                    },
                    //cardCommissionerUid: {
                    //    required: "卡管专员不能为空"
                    //}
                },
            });

        });

        function save() {
            if (!validator.form()) {
                return false;
            }

            var cardMerchant = {};
            cardMerchant.Cmname = $("input[name='cmname']").val();
            cardMerchant.Cmcode = $("input[name='cmcode']").val();
            cardMerchant.Cmcredit = $("#cmcredit option:selected").val();
            //cardMerchant.CardCommissionerUid = $("#cardCommissionerUid").val();
            cardMerchant.DelayRate = $("input[name='delayRate']").val() > 100 ? 100 : $("input[name='delayRate']").val();
            cardMerchant.Remark = $.trim($("textarea[name='remark']").val())

            FlashPay.Util.Ajax({
                url: '/CardMerchant/Insert',
                type: 'POST',
                data: JSON.stringify(cardMerchant),
                dataType: 'json',
                contentType: 'application/json; charset=utf-8',
                success: function (data) {
                    if (!data.success) {
                        FlashPay.UI.Tip_short_warning("添加失败," + data.errorMessage == null ? "系统已存在相同卡商名称或卡商代号！" : data.errorMessage);
                    } else {
                        FlashPay.UI.DialogOpener().Tip_success("添加成功！");
                        FlashPay.UI.DialogOpener().doSearch();
                        FlashPay.UI.CloseDialog();
                    }
                },
                error: function (json) {
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试。");
                }
            });
        }

        $("input[name='delayRate']").autocomplete({
            minLength: 1,
            source: function () {
                if ($("input[name='delayRate']").val() > 100) {
                    $("input[name='delayRate']").val(100);
                }
            }
        });
    </script>
</body>
</html>